//
//  DiseaseListViewController.m
//  MedicineBox
//
//  Created by dllo on 15/8/24.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "DiseaseListViewController.h"
#import "DrugListViewController.h"
#import "DKNightVersion.h"
#import "UIImageView+NightImage.h"
@interface DiseaseListViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, retain) NSMutableArray *array;
@property (nonatomic, retain) NSMutableDictionary *dic;


@end

@implementation DiseaseListViewController

-(void)dealloc
{
    [_array release];
    [_dic release];
    [super dealloc];
}


- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.dic = [NSMutableDictionary dictionaryWithCapacity:10];
        self.array = [NSMutableArray arrayWithCapacity:10];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.view.nightBackgroundColor = UIColorFromRGB(0x343434);
    [self createNavigation];
    [self handleData];
    [self createView];
}

#pragma mark -
#pragma mark 设置导航栏
- (void)createNavigation
{
    UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
    navView .backgroundColor = [UIColor colorWithRed:56/255.0 green:185/255.0 blue:94 / 255.0 alpha:0.5];
    navView.nightBackgroundColor = UIColorFromRGB(0x444444);
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 63, self.view.frame.size.width, 0.5)];
    line.backgroundColor = [UIColor whiteColor];
    [navView addSubview:line];
    [self.view addSubview:navView];
    [navView release];
    
//标题
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 100) / 2, 30, 100, 30)];
    titleLabel.text = @"对症下药";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor orangeColor];
    titleLabel.nightTextColor = [UIColor whiteColor];
    [navView addSubview:titleLabel];
    [titleLabel release];
//返回
    
    UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(10 , 30, 60, 30)];
    [navView addSubview:backButton];
    [backButton setTitle:@"返回" forState:UIControlStateNormal];
    [backButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [backButton release];
}

- (void)buttonAction:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - 
#pragma mark - 数据处理

- (void)handleData
{
    NSString *file = [[NSBundle mainBundle] pathForResource:@"Disease" ofType:@"plist"];
    self.dic = [NSMutableDictionary dictionaryWithContentsOfFile:file];
    self.array = [[self.dic allKeys] sortedArrayUsingSelector:@selector(compare:)].mutableCopy;
}
#pragma mmark -
#pragma mark 创建tableView
- (void)createView{
    
    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStylePlain];
    [self.view addSubview:table];
    table.delegate = self;
    table.dataSource = self;
   
    table.nightBackgroundColor = UIColorFromRGB(0x343434);
    table.nightSeparatorColor = [UIColor whiteColor];
    [DKNightVersionManager addClassToSet:self.class];
    
    [table release];
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.array.count;
}

//每个分区行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSString *key = [self.array objectAtIndex:section];
    NSArray *array = [self.dic objectForKey:key];
   
    return array.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *key = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:key];
    if (!cell) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:key] autorelease];
    }
    cell.nightBackgroundColor = UIColorFromRGB(0x343434);
    NSString *key1 = [self.array objectAtIndex:indexPath.section];
    NSArray *array = [self.dic objectForKey:key1];
    cell.textLabel.text = [array objectAtIndex:indexPath.row];
    cell.textLabel.nightTextColor = [UIColor whiteColor];
    return cell;
}

//索引
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    return self.array;
}
//头标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    
    return [self.array objectAtIndex:section];
    
}
#pragma mark -
#pragma mark - 点击选择事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSArray *array = @[@"%E9%98%BF%E7%B1%B3%E5%B7%B4%E7%97%85",
                       @"%E8%89%BE%E6%BB%8B%E7%97%85",
                       @"%E7%96%A4%E7%97%95",
                       @"%E7%99%BD%E5%B8%A6%E5%BC%82%E5%B8%B8",
                       @"%E7%99%BD%E7%99%9C%E9%A3%8E",
                       @"%E7%99%BD%E7%BB%86%E8%83%9E%E5%87%8F%E5%B0%91",
                       @"%E7%99%BD%E8%A1%80%E7%97%85",
                       @"%E9%BC%BB%E5%92%BD%E7%99%8C",
                       @"%E6%89%81%E6%A1%83%E4%BD%93%E7%82%8E",
                       @"%E4%B8%99%E8%82%9D",
                       @"%E7%97%85%E6%AF%92%E6%80%A7%E6%84%9F%E5%86%92",
                       @"%E4%BA%A7%E5%90%8E%E7%96%BE%E7%97%85",
                       @"%E7%97%B4%E5%91%86",
                       @"%E5%B8%A6%E7%8A%B6%E7%96%B1%E7%96%B9",
                       @"%E8%83%86%E7%BB%93%E7%9F%B3",
                       @"%E8%83%86%E5%9B%8A%E7%82%8E",
                       @"%E4%BD%8E%E8%A1%80%E9%92%BE ",
                       @"%E4%BD%8E%E8%A1%80%E7%B3%96",
                       @"%E6%BB%B4%E8%99%AB%E7%97%85",
                       @"%E7%99%AB%E7%97%AB",
                       @"%E5%A4%9A%E5%8A%A8%E7%97%87",
                       @"%E5%A4%9A%E5%8F%91%E6%80%A7%E7%A5%9E%E7%BB%8F%E7%82%8E",
                       @"%E8%80%B3%E9%B8%A3%E8%80%B3%E8%81%8B",
                       @"%E8%82%A5%E8%83%96%E7%97%87",
                       @"%E8%82%BA%E7%99%8C",
                       @"%E9%A3%8E%E6%B9%BF%E7%96%BC%E7%97%9B",
                       @"%E8%82%9D%E7%99%8C",
                       @"%E8%82%9D%E7%BA%A4%E7%BB%B4%E5%8C%96",
                       @"%E8%82%9D%E6%80%A7%E8%84%91%E7%97%85",
                       @"%E8%82%9D%E7%A1%AC%E5%8C%96",
                       @"%E9%AB%98%E8%A1%80%E5%8E%8B",
                       @"%E9%AB%98%E8%A1%80%E8%84%82",
                       @"E6%9B%B4%E5%B9%B4%E6%9C%9F%E7%BB%BC%E5%90%88%E7%97%87",
                       @"%E5%AE%AB%E9%A2%88%E7%99%8C",
                       @"%E8%82%A1%E9%AA%A8%E5%A4%B4%E5%9D%8F%E6%AD%BB",
                       @"%E9%AA%A8%E7%99%8C",
                       @"%E9%AA%A8%E5%85%B3%E8%8A%82%E7%82%8E",
                       @"%E9%AA%A8%E8%B4%A8%E5%A2%9E%E7%94%9F",
                       @"%E8%BF%87%E6%95%8F",
                       @"%E7%BA%A2%E6%96%91%E7%8B%BC%E7%96%AE",
                       @"%E6%BB%91%E7%B2%BE%E9%81%97%E7%B2%BE",
                       @"%E7%81%B0%E6%8C%87%E7%94%B2",
                       @"%E8%9B%94%E8%99%AB%E7%97%85",
                       @"%E8%82%8C%E8%82%89%E5%85%B3%E8%8A%82%E7%97%9B",
                       @"%E8%84%8A%E6%9F%B1%E4%BE%A7%E5%BC%AF",
                       @"%E7%94%B2%E7%8A%B6%E8%85%BA%E5%8A%9F%E8%83%BD%E5%87%8F%E9%80%80",
                       @"%E7%94%B2%E7%8A%B6%E8%85%BA%E5%8A%9F%E8%83%BD%E4%BA%A2%E8%BF%9B",
                       @"%E7%94%B2%E7%8A%B6%E8%85%BA%E7%98%A4",
                       @"%E5%B0%96%E9%94%90%E6%B9%BF%E7%96%A3",
                       @"%E8%82%A9%E5%91%A8%E7%82%8E",
                       @"%E7%96%96%E8%82%BF%E7%96%A5%E7%96%AE",
                       @"%E7%BB%93%E8%82%A0%E7%99%8C",
                       @"%E7%BB%93%E6%A0%B8%E7%97%85",
                       @"%E7%B2%BE%E7%A5%9E%E5%88%86%E8%A3%82%E7%97%87",
                       @"%E9%A2%88%E6%A4%8E%E7%97%85",
                       @"%E9%85%92%E7%B2%BE%E8%82%9D",
                       @"%E9%85%92%E6%B8%A3%E9%BC%BB",
                       @"%E5%8F%A3%E8%88%8C%E7%94%9F%E7%96%AE",
                       @"%E6%BA%83%E7%96%A1%E7%B1%BB",
                       @"%E5%8F%A3%E8%88%8C%E7%94%9F%E7%96%AE",
                       @"%E6%B7%8B%E5%B7%B4%E7%99%8C",
                       @"%E6%B7%8B%E7%97%85",
                       @"%E8%9E%A8%E8%99%AB%E6%84%9F%E6%9F%93",
                       @"%E6%85%A2%E6%80%A7%E8%82%BE%E5%B0%8F%E7%90%83%E7%82%8E",
                       @"%E7%94%B7%E6%80%A7%E4%B8%8D%E8%82%B2",
                       @"%E8%9B%B2%E8%99%AB%E7%97%85",
                       @"%E8%84%91%E7%99%8C",
                       @"%E8%84%91%E8%A1%80%E7%AE%A1%E7%97%85%EF%BC%88%E4%B8%AD%E9%A3%8E%EF%BC%89",
                       @"%E5%86%85%E5%88%86%E6%B3%8C%E5%A4%B1%E8%B0%83",
                       @"%E5%B0%BF%E5%B4%A9%E7%97%87",
                       @"%E5%B0%BF%E9%81%93%E7%BB%93%E7%9F%B3",
                       @"%E5%B0%BF%E6%AF%92%E7%97%87",
                       @"%E5%B0%BF%E8%B7%AF%E6%84%9F%E6%9F%93",
                       @"%E6%89%AD%E4%BC%A4%E6%8C%AB%E4%BC%A4%E5%86%BB%E4%BC%A4",
                       @"%E7%96%9F%E7%96%BE",
                       @"%E5%A5%B3%E6%80%A7%E4%B8%8D%E5%AD%95",
                       @"%E5%B8%95%E9%87%91%E6%A3%AE",
                       @"%E8%86%80%E8%83%B1%E7%99%8C",
                       @"%E8%86%80%E8%83%B1%E7%82%8E",
                       @"%E7%9A%AE%E8%82%A4%E7%99%8C",
                       @"%E7%9A%AE%E7%82%8E%E6%B9%BF%E7%96%B9",
                       @"%E5%81%8F%E5%A4%B4%E7%96%BC",
                       @"%E8%B4%AB%E8%A1%80",
                       @"%E6%B0%94%E7%AE%A1%E7%82%8E",
                       @"%E5%89%8D%E5%88%97%E8%85%BA%E7%99%8C",
                       @"%E5%BC%BA%E8%BF%AB%E7%97%87",
                       @"%E5%BC%BA%E7%9B%B4%E6%80%A7%E8%84%8A%E6%9F%B1%E7%82%8E",
                       @"%E4%B9%B3%E8%85%BA%E7%99%8C",
                       @"%E4%B9%B3%E8%85%BA%E5%A2%9E%E7%94%9F",
                       @"%E8%89%B2%E6%96%91",
                       @"%E7%83%A7%E4%BC%A4%E7%83%AB%E4%BC%A4",
                       @"%E5%B0%91%E7%B2%BE%E6%97%A0%E7%B2%BE",
                       @"%E5%B0%84%E7%B2%BE%E6%97%A0%E5%8A%9B",
                       @"%E7%A5%9E%E7%BB%8F%E8%A1%B0%E5%BC%B1",
                       @"%E7%A5%9E%E7%BB%8F%E6%8D%9F%E4%BC%A4",
                       @"%E7%A5%9E%E7%BB%8F%E6%80%A7%E7%96%BC%E7%97%9B",
                       @"%E8%82%BE%E7%99%8C",
                       @"%E8%82%BE%E7%97%85%E7%BB%BC%E5%90%88%E5%BE%81",
                       @"%E8%82%BE%E7%A7%AF%E6%B0%B4",
                       @"%E8%82%BE%E7%BB%93%E7%9F%B3",
                       @"%E8%82%BE%E6%B0%94%E8%A1%B0%E5%BC%B1",
                       @"%E8%82%BE%E7%82%8E",
                       @"%E7%94%9F%E6%AE%96%E5%99%A8%E7%96%B1%E7%96%B9",
                       @"%E5%A4%B1%E7%9C%A0",
                       @"%E6%B9%BF%E6%AF%92%E7%96%AE",
                       @"%E9%A3%9F%E9%81%93%E7%99%8C",
                       @"%E6%89%8B%E8%B6%B3%E7%9A%B2%E8%A3%82",
                       @"%E8%BE%93%E5%B0%BF%E7%AE%A1%E7%BB%93%E7%9F%B3",
                       @"%E4%B8%9D%E8%99%AB%E7%97%85 ",
                       @"%E7%B3%96%E5%B0%BF%E7%97%85",
                       @"%E7%97%9B%E9%A3%8E",
                       @"%E7%97%9B%E7%BB%8F",
                       @"%E5%A4%B4%E7%97%9B%E5%A4%B4%E6%99%95",
                       @"%E8%84%B1%E5%8F%91%E6%96%91%E7%A7%83",
                       @"%E8%83%83%E7%99%8C",
                       @"%E8%83%83%E8%84%98%E7%96%BC%E7%97%9B",
                       @"%E5%B0%8F%E5%84%BF%E8%84%91%E7%98%AB",
                       @"%E5%BF%83%E8%84%8F%E5%8F%8A%E5%86%A0%E8%84%89%E7%96%BE%E7%97%85",
                       @"%E7%99%A3%E7%97%87%EF%BC%88%E9%93%B6%E5%B1%91%E7%97%85%EF%BC%89",
                       @"%E8%A1%80%E5%B0%8F%E6%9D%BF%E5%87%8F%E5%B0%91",
                       @"%E8%8D%A8%E9%BA%BB%E7%96%B9",
                       @"%E7%89%99%E7%97%9B",
                       @"%E5%92%BD%E7%97%9B%E9%9F%B3%E5%93%91",
                       @"%E7%82%8E%E7%97%87%E7%B1%BB",
                       @"%E9%98%B3%E7%97%BF%E6%97%A9%E6%B3%84",
                       @"%E8%85%B0%E8%82%8C%E5%8A%B3%E6%8D%9F",
                       @"%E8%85%B0%E6%A4%8E%E9%97%B4%E7%9B%98%E7%AA%81%E5%87%BA",
                       @"%E8%83%B0%E8%85%BA%E7%99%8C",
                       @"%E8%83%B0%E8%85%BA%E7%82%8E",
                       @"%E4%B9%99%E8%82%9D",
                       @"%E6%8A%91%E9%83%81%E7%97%87",
                       @"%E9%98%B4%E9%81%93%E7%82%8E",
                       @"%E6%9C%88%E7%BB%8F%E4%B8%8D%E8%B0%83",
                       @"%E6%99%95%E8%BD%A6%E6%99%95%E8%88%B9",
                       @"E8%BF%90%E5%8A%A8%E7%A5%9E%E7%BB%8F%E5%85%83%E7%97%85",
                       @"%E8%84%82%E8%82%AA%E8%82%9D",
                       @"%E6%AD%A2%E5%92%B3%E7%A5%9B%E7%97%B0",
                       @"%E6%AD%A2%E6%B3%BB%E7%B1%BB",
                       @"%E7%97%94%E7%96%AE%E4%BE%BF%E7%A7%98%E4%BE%BF%E8%A1%80",
                       @"%E4%B8%AD%E9%A3%8E%E5%81%8F%E7%98%AB",
                       @"%E5%91%A8%E5%9B%B4%E8%A1%80%E7%AE%A1%E7%96%BE%E7%97%85",
                       @"%E5%8A%A9%E6%B6%88%E5%8C%96%E7%B1%BB",
                       @"%E5%AD%90%E5%AE%AB%E8%82%8C%E7%98%A4",
                       @"%E5%AD%90%E5%AE%AB%E5%86%85%E8%86%9C%E5%BC%82%E4%BD%8D",
                       @"%E5%9D%90%E9%AA%A8%E7%A5%9E%E7%BB%8F%E7%97%9B",
                       @"%E5%BA%A7%E7%96%AE%E7%B2%89%E5%88%BA"];
    
    DrugListViewController *drug = [[DrugListViewController alloc] init];
    drug.word = [array objectAtIndex:indexPath.row];
    [self presentViewController:drug animated:YES completion:nil];
    [drug release];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
